package com.tianzeculture.stagebao.activity.personal;

import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.tianzeculture.stagebao.R;
import com.tianzeculture.stagebao.activity.home.MainActivity;
import com.tianzeculture.stagebao.activity.login.LoginActivity;
import com.tianzeculture.stagebao.activity.mine.SettingReplyActivity;
import com.tianzeculture.stagebao.base.BaseActivity;
import com.tianzeculture.stagebao.network.enity.MSG;
import com.tianzeculture.stagebao.util.CleanMessageUtil;
import com.tianzeculture.stagebao.util.StatusBarUtil;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by Administrator on 2018/6/22 0022.
 * 设置
 */

public class SettingActivity extends BaseActivity {
    @BindView(R.id.tvTitle)
    TextView tvTitle;

    @BindView(R.id.tvModifyPwd)
    TextView tvModifyPwd;
    @BindView(R.id.tvClean)
    TextView tvClean;
    @BindView(R.id.tvChangePhone)
    TextView tvChangePhone;
    @BindView(R.id.version)
    TextView version;
    @BindView(R.id.tvReply)
    TextView tvReply;
    @BindView(R.id.layoutClean)
    LinearLayout layoutClean;
    @BindView(R.id.layoutVersion)
    LinearLayout layoutVersion;
    @BindView(R.id.btnLoginOut)
    Button btnLoginOut;


    @Override
    public void initUI() {
        super.initUI();
        StatusBarUtil.setWindowStatusBarColor(this, R.color.colorGray_F8);
        tvTitle.setText("设置");
        version.setText(packageName(this));
        try {
            tvClean.setText(CleanMessageUtil.getTotalCacheSize(this));
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
        }
    }

    @OnClick({R.id.tvModifyPwd, R.id.tvChangePhone, R.id.layoutClean, R.id.layoutVersion, R.id.btnLoginOut, R.id.tvReply})
    public void onclick(View view) {
        switch (view.getId()) {
            case R.id.tvModifyPwd:
                startActivity(new Intent(SettingActivity.this, ModifyPwdActivity.class));
                break;
            case R.id.tvChangePhone:
                startActivity(new Intent(SettingActivity.this, ChangePhoneActivity.class));
                break;
            case R.id.layoutClean:
                CleanMessageUtil.clearAllCache(this);
                try {
                    tvClean.setText(CleanMessageUtil.getTotalCacheSize(this));
                } catch (Exception e) {
                    e.printStackTrace();
                } finally {
                }
                break;
            case R.id.layoutVersion:
                break;
            case R.id.btnLoginOut:
                startActivity(new Intent(this, LoginActivity.class));
                MainActivity.instance.finish();
                break;
            case R.id.tvReply:
                startActivity(new Intent(this, SettingReplyActivity.class));
                break;
        }
    }

    public static String packageName(Context context) {
        PackageManager manager = context.getPackageManager();
        String name = null;
        try {
            PackageInfo info = manager.getPackageInfo(context.getPackageName(), 0);
            name = info.versionName;
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }

        return name;
    }

    @Override
    public void refreshUI(int taskId, MSG msg) {
        super.refreshUI(taskId, msg);
    }

    @Override
    protected int getLayoutResID() {
        return R.layout.activity_setting;
    }
}
